<?php

/**
 * 管理后台
 * 自动生成代码
 * 
 * /Apps/Mp/Controller/IndexController.class.php
 * 
 * Zix @ 2015-06-08
 */

namespace Mp\Controller;

use Common\Service\GenerateCodeService;

class GenerateCodeController extends MpController {

  public function index() {
    $data = $this->_init_data();
    $data['module_name'] = '自动生成代码';

    $data['config'] = array(
      'menu_id' => $this->menu_id ,
      'get_tableinfo_url' => U($this->base_path . 'get_tableinfo'),
      'get_model_info_url' => U($this->base_path . 'get_model_info'),
      'add_model_url' => U($this->base_path . 'add_model'),
      'get_service_info_url' => U($this->base_path . 'get_service_info'),
      'add_service_url' => U($this->base_path . 'add_service'),
      'get_controller_info_url' => U($this->base_path . 'get_controller_info'),
      'add_controller_url' => U($this->base_path . 'add_controller'),
      'get_js_info_url' => U($this->base_path . 'get_js_info'),
      'add_js_url' => U($this->base_path . 'add_js'),
      'get_view_info_url' => U($this->base_path . 'get_view_info'),
      'add_view_url' => U($this->base_path . 'add_view'),
    );

    $this->display_with_layout($data, 'GenerateCode:index');
  }

  function get_tableinfo() {
    $tablename = I('param.tablename');

    $GeneratecCode = GenerateCodeService::instance();

    $data['rows'] = $GeneratecCode->get_by_tablename($tablename);

    $this->ajaxReturn($data);
  }

  function get_model_info() {
    $tablename = I('param.tablename');
    $GeneratecCode = GenerateCodeService::instance();

    $ret = $GeneratecCode->get_model_info($tablename);

    $this->ajaxReturn($ret);
  }

  function add_model() {
    $data = I('post.');
    $GeneratecCode = GenerateCodeService::instance();
    $data['author'] = $this->auth['username'];
    $data['date'] = date('Y-m-d');
    $ret = $GeneratecCode->add_model($data);

    $this->ajaxReturn($ret);
  }

  function get_service_info() {
    $tablename = I('param.tablename');
    $GeneratecCode = GenerateCodeService::instance();
    $ret = $GeneratecCode->get_service_info($tablename);
    $this->ajaxReturn($ret);
  }

  function add_service() {
    $data = I('post.');
    $GeneratecCode = GenerateCodeService::instance();
    $data['author'] = $this->auth['username'];
    $data['date'] = date('Y-m-d');
    $ret = $GeneratecCode->add_service($data);
    $this->ajaxReturn($ret);
  }

  function get_controller_info() {
    $tablename = I('param.tablename');
    $GeneratecCode = GenerateCodeService::instance();

    $ret = $GeneratecCode->get_controller_info(MODULE_NAME, $tablename);
    $this->ajaxReturn($ret);
  }

  function add_controller() {
    $data = I('post.');
    $GeneratecCode = GenerateCodeService::instance();
    $data['author'] = $this->auth['username'];
    $data['date'] = date('Y-m-d');
    $ret = $GeneratecCode->add_controller($data);
    $this->ajaxReturn($ret);
  }

  function get_js_info() {
    $tablename = I('param.tablename');
    $GeneratecCode = GenerateCodeService::instance();

    $ret = $GeneratecCode->get_js_info(MODULE_NAME, $tablename);
    $ret['type'] = I('param.type');
    $this->ajaxReturn($ret);
  }

  function add_js() {
    $data = I('post.');
    $GeneratecCode = GenerateCodeService::instance();
    $data['author'] = $this->auth['username'];
    $data['date'] = date('Y-m-d');
    $ret = $GeneratecCode->add_js($data);
    $this->ajaxReturn($ret);
  }

  function get_view_info() {
    $tablename = I('param.tablename');
    $GeneratecCode = GenerateCodeService::instance();

    $ret = $GeneratecCode->get_view_info(MODULE_NAME, $tablename);
    $ret['type'] = I('param.type');
    $this->ajaxReturn($ret);
  }

  function add_view() {
    $data = I('post.');
    $GeneratecCode = GenerateCodeService::instance();
    $data['author'] = $this->auth['username'];
    $data['date'] = date('Y-m-d');
    $ret = $GeneratecCode->add_view($data);
    $this->ajaxReturn($ret);
  }

}
